package cn.uestc.labhms.modules.hms.controller;

import cn.uestc.labhms.common.annotation.SysLog;
import cn.uestc.labhms.common.utils.R;
import cn.uestc.labhms.modules.hms.entity.Vo.CommonConditionVo;
import cn.uestc.labhms.modules.hms.entity.Vo.ViewVo;
import cn.uestc.labhms.modules.hms.service.ViewService;
import cn.uestc.labhms.modules.hms.util.HMSPageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Mutz
 */
@RestController
public class ViewController {
    @Autowired
    private ViewService viewService;
    @GetMapping("/get/hms_view/data")
    @SysLog("查询视图")
    public R getViewData(@Validated ViewVo viewVo) {
        HMSPageUtils viewData = viewService.getViewData(viewVo);
        return R.ok().put("data", viewData);
    }
    @GetMapping("/get/hms_view/name/list")
    public R getViewNameList() {
        List<String> viewNameList = viewService.getViewNameList();
        return R.ok().put("data", viewNameList);
    }
    @GetMapping("/get/hms_view/fields")
    public R getViewFields(String viewName) {
        CommonConditionVo viewField = viewService.getViewField(viewName);
        return R.ok().put("data", viewField);
    }
    @GetMapping("/get/hms_view/field/find")
    public R getFieldFind(@RequestParam(required = false) String viewName,
                          @RequestParam(required = false) List<String> keys,
                          @RequestParam(required = false) List<String> vals,
                          @RequestParam(required = false) Integer curPage) {
        HMSPageUtils viewWithField = viewService.getViewWithField(viewName, keys, vals, curPage);
        return R.ok().put("data", viewWithField);
    }
}
